var checkUrl = "/check";
var checkNameAndCode = "/checkNameAndCode";
var fotGetPasswordUrl = "/fotGetPassword";
var sendgetpwdcode = "/sendgetpwdcode";
var indexUrl = "/main";
if (typeof window.IS_MOBILE !== "undefined") {
    checkUrl = "/mobile/check";
    checkNameAndCode = "/mobile/checkNameAndCode";
    fotGetPasswordUrl = "/mobile/fotGetPassword";
    sendgetpwdcode = "/mobile/sendgetpwdcode";
    indexUrl = "/mobile/main"
}
$(function() {
    $("input[name=username]").change(function() {
        var a = $(this).val();
        if (a != "") {
            $.get(checkUrl, {
                username: $(this).val()
            }, function(b) {
                if (!b) {
                    dialog.error("消息", "你查找的登录名称不存在！")
                }
            })
        }
    })
});
function sendCode(a, b) {
    $.get(sendgetpwdcode, {
        type: 0,
        destination: a,
        name: b
    }, function(c) {
        if (c.success) {
            dialog.alert1("消息", "验证码已发送，请注意查收！", null, "editpwd?name=" + b)
        } else {
            dialog.error("消息", "验证码发送错误，请重新发送或联系客服!")
        }
    })
}
function checkInfo() {
    var c = $.trim($("input[name=username]").val());
    var a = $.trim($('input[name="mobile"]').val());
    
    if (c == "") {
        dialog.error("消息", "登录名称不能为空！");
        return false
    }
    if (a == "") {
        dialog.error("消息", "请输入你绑定的手机号！");
        return false
    }

    $.post('forget_password', {
        username: c,
        mobile: a
    }, function(d) {
        if (d.success) {
        	dialog.alert("消息", d.message);
        	$("#forget").hide();
        	$("#forget2").show();
			$(".step1").removeClass("on");
			$(".step2").addClass("on");
        } else {
            dialog.error("消息", d.message)
        }
    },'json')
}
function fotGetPassword() {
    var b = $.trim($("#pwd").val());
    var a = $.trim($("#ckPwd").val());
    var c = $.trim($("#code").val());
    var d = $.trim($("input[name=username]").val());
    if (b == "") {
        dialog.error("消息", "请输入新密码！");
        return false
    }
    if(b.length<6 || b.length>20){
          dialog.error("消息", "6-20个字母、数字或组合组成，区分大小写！");
          return
        }
    if (b != a) {
        dialog.error("消息", "新设密码 和 新设密码确认 不一样！(确认大小写是否相同)");
        $("#ckPassword").focus();
        return false
    }
    if (c == "") {
        dialog.error("消息", "验证码不能为空！");
        return false
    }
    
    $.post('fotGetPassword', {
        name: d,
        code: c,
        password: b
    }, function(e) {
        if (e.success) {
			$(".step2").removeClass("on");
			$(".step3").addClass("on");
            dialog.alert1("消息", e.message, null, '/index.php/Index/index')
        } else {
            dialog.error("消息", e.message)
        }
    },'json')
}
;